<template>
    <BTextButton :type="v ? 'error' : 'primary'" :loading="loading" @click="setR">{{ v ? '取消推荐' : '设为推荐' }}</BTextButton>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { saveApi } from '@/api/Apps';

    const props = defineProps<{
        id : number;
        recommend : boolean;
    }>()

    const emit = defineEmits<{
        (e : 'update:recommend', recommend : boolean) : void;
    }>()

    const v = ref(props.recommend)

    const loading = ref(false)

    async function setR() {
        loading.value = true
        const res = await saveApi({id : props.id, recommend : !v.value})
        v.value = !v.value
        loading.value = false

        emit('update:recommend', v.value)
    }

</script>